package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.OverflowListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/23 18:43
 */
@RestController
@RequestMapping("overflowListGoods")
public class OverflowListController {
    @Autowired
    private OverflowListService overflowListService;

    //    http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015（报溢单号）
    @PostMapping("save")
    public ServiceVO save(OverflowList overflowList, String overflowListGoodsStr, HttpSession session) {
        User user = (User) session.getAttribute("currentUser");
        if (user == null) {
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
        overflowList.setUserId(user.getUserId());
        return overflowListService.save(overflowList, overflowListGoodsStr);
    }

    //    http://localhost:8080/overflowListGoods/list
    @PostMapping("list")
    public Map<String, Object> list(String sTime, String eTime) {
        return overflowListService.list(sTime, eTime);
    }

//    http://localhost:8080/overflowListGoods/goodsList
    @PostMapping("goodsList")
    public Map<String, Object> goodsList(Integer overflowListId) {
        return overflowListService.goodsList(overflowListId);
    }
}
